Adopt SwiftLint: pre-commit hook + CI + violation cleanup#5
Merged
Conversation
Adds a shareable pre-commit hook under scripts/hooks/ that auto-fixes staged .swift files, refuses to run when staged files have unstaged edits, and strict-lints what remains. scripts/install-hooks.sh wires core.hooksPath -> scripts/hooks (one-time per clone). CI runs the same Homebrew SwiftLint on macos-latest so the binary and rule set match the local hook — no version drift between dev and CI. Path filter scopes the workflow to .swift / .swiftlint.yml / the workflow file itself. Minimal .swiftlint.yml at the root includes Sources + Tests; ShellKit is a library-only package so there's no app target to list. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
132 → 0. Auto-fix cleared the easy 24 (commas, braces, trailing newlines). Remaining 108 broken down per the iBash field-notes triage: - 78 identifier_name: all local-variable renames — no public-API parameter labels touched (every short-name violation is on a let, closure param, or case binding). Common renames: sb → sandbox, rc → result, h → lower/headStr, i/v → index/value, n → count, bp/ok → buffer/success, e → entry. - 15 optional_data_string_conversion: library streaming-decode sites get surgical `// swiftlint:disable:next` with reasons — the rule's preferred failable form would drop bytes on partial UTF-8 chunks, which is wrong for InputSource/OutputSink contracts. Test sites switched to the rule's preferred `String(bytes:encoding:) ?? ""` form (cleaner than a disable per call site). - 3 large_tuple: new local structs PrivateIP.IPv4Address (4-octet return shape) and HostInfo.UnameInfo (5-field uname result). - 2 function_body_length: DefaultProcessLauncher.launch split into four private helpers (collectInputBytes, subprocessExecutable, subprocessEnvironment, resolveWorkingDirectory). HostInfo.real split into realUserAndFull + realSupplementaryGroups. - 5 function_parameter_count: surgical disables on the launcher protocol + 4 conformers. The 7-arg signature mirrors POSIX exec (program + args + env + cwd + stdin + stdout + stderr); bundling into a struct is a breaking protocol change for every ShellKit consumer for no behavioural gain. - 1 cyclomatic_complexity: PrivateIP.isPrivateIPv4 refactored into a top-half that handles whole-first-octet ranges and a private isReservedIPv4OctetPair helper for the octet-pair ranges (link- local, 172.16/12, 192.168/16, 192.0/24, CGNAT). No disable. - 3 for_where, 1 nesting (Entry.State, disabled with reason), remaining mechanical rewrites. `swift build` clean, `swift test` 33/33 passing, `swiftlint --strict` exit 0. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adopts SwiftLint on ShellKit, following the field-notes pattern (shareable in-repo hook + CI workflow + initial violation cleanup).
scripts/hooks/pre-commit, installed viascripts/install-hooks.sh) — auto-fixes staged.swiftfiles, refuses to run when staged files have unstaged edits, then strict-lints what remains. CI-skip via\$CIenv var..github/workflows/swiftlint.yml) — macOS + Homebrew SwiftLint so the binary/rule-set matches the hook (no version drift). Path-filtered to.swift/.swiftlint.yml/ the workflow file..swiftlint.yml— minimal:Sources+Testsincluded;.build/.swiftpmexcluded. No app target on this library package.The two commits split cleanly along that boundary:
SwiftLint: adopt as pre-commit hook and CI workflow— infrastructure onlySwiftLint: clear initial violations to pass --strict— 21-file cleanupCleanup breakdown (per iBash field-notes triage)
swiftlint --fix(commas/braces/trailing newlines/implicit-optional-init)identifier_namesb→sandbox,rc→result,h→lower,i/v→index/value,n→count/name,bp/ok→buffer/success,e→entry, etc. No public-API breakage.optional_data_string_conversion// swiftlint:disable:nextwith "lossy by design" reason. Test sites: switched toString(bytes:encoding:) ?? \"\"(rule's preferred form).large_tuplePrivateIP.IPv4Address,HostInfo.UnameInfo.function_body_lengthDefaultProcessLauncher.launchsplit into 4 helpers;HostInfo.realsplit intorealUserAndFull+realSupplementaryGroups.function_parameter_countcyclomatic_complexityisPrivateIPv4refactored (top-half handles whole-first-octet ranges, helper handles octet-pair ranges) — no disable needed.for_wherefor X in Y where Z.nestingEntry.Statedisabled with reason — meaningful grouping.Test plan
swift build --build-testscleanswift test— 33/33 passingswiftlint lint --strictexit 0scripts/install-hooks.shonce to activate the hook locally (or skip it — CI catches anything that lands without the hook).Reviewer notes
core.hooksPathis set byscripts/install-hooks.sh, which is a one-time-per-clone explicit step.swiftlint:disable:thison the protocol method'sfunc launch(line); all 4 conforming implementations keep the same 7-parameter shape.ShellTests.swift(4trywarnings onwithCurrentcalls) are unrelated to this branch — they existed onmainbefore this PR.🤖 Generated with Claude Code